﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MapEntities;
using ServerPlatform.Web;

namespace WebApp.Controls
{
    public partial class ShapeColoringInfoEditor : BaseDataEditor<ShapeColoringInfo>
    {

        public string ColorTitle
        {
            get
            {
                return Label1.Text;
            }
            set
            {
                Label1.Text = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                foreach (string xcolor in Enum.GetNames(typeof(System.Drawing.KnownColor)))
                {
                    ctlColorList.Items.Add(new ListItem(xcolor));
                }
                foreach (string xmode in Enum.GetNames(typeof(ColoringMode)))
                {
                    ctlColoringMode.Items.Add(new ListItem(xmode, xmode));
                }
                foreach (string xlevel in Enum.GetNames(typeof(TransparencyLevel)))
                {
                    ctlTransparencyLevel.Items.Add(new ListItem(xlevel, xlevel));
                }
            }
        }

        public override void ClearEditor()
        {
            ctlColoringMode.SelectedIndex = 0;
            ctlColorList.SelectedIndex = 0;
            ctlTransparencyLevel.SelectedIndex = 0;
        }

        protected override void ShowEntity(ShapeColoringInfo entity)
        {
            ctlColoringMode.SelectedIndex = ctlColoringMode.Items.IndexOf(ctlColoringMode.Items.FindByValue(entity.Mode.ToString()));
            ctlColorList.SelectedIndex = ctlColorList.Items.IndexOf(ctlColorList.Items.FindByText(entity.ColorName.ToString()));
            ctlTransparencyLevel.SelectedIndex = ctlTransparencyLevel.Items.IndexOf(ctlTransparencyLevel.Items.FindByValue(entity.Level.ToString()));
        }

        public override ShapeColoringInfo GetEntity()
        {
            ShapeColoringInfo xcolorinfo = Current;
            xcolorinfo.ColorName = (System.Drawing.KnownColor)Enum.Parse(typeof(System.Drawing.KnownColor), ctlColorList.SelectedValue);
            xcolorinfo.Level = (TransparencyLevel)Enum.Parse(typeof(TransparencyLevel), ctlTransparencyLevel.SelectedValue);
            xcolorinfo.Mode = (ColoringMode)Enum.Parse(typeof(ColoringMode), ctlColoringMode.SelectedValue);
            return xcolorinfo;

        }
    }   
}